#!/usr/bin/env python3.6

import os
import numpy as np
import rospy
from cv_bridge import CvBridge
from sensor_msgs.msg import Image
import cv2

current_file_path = os.path.abspath(__file__)
directory = os.path.dirname(current_file_path)

rospy.init_node('image_publisher')
image_pub = rospy.Publisher('/MVcam/image', Image, queue_size=1)

cv_image = cv2.imread(directory + '/manyperson.jpeg')

bridge = CvBridge()

rate = rospy.Rate(25) 
font = cv2.FONT_HERSHEY_SIMPLEX
font_scale = 10
font_color = (255, 0, 0)  # White color
line_thickness = 2

while not rospy.is_shutdown():
    random_number = np.random.randint(0, 100)  # Replace the range with your desired limits
    copied_image = np.copy(cv_image)
    text = str(random_number)
    text_size, _ = cv2.getTextSize(text, font, font_scale, line_thickness)
    text_origin = (10, text_size[1] + 10)  # Top-left corner position of the text
    cv2.putText(copied_image, text, text_origin, font, font_scale, font_color, line_thickness)

    ros_image = bridge.cv2_to_imgmsg(copied_image, "bgr8")

    image_pub.publish(ros_image)
    rate.sleep()

cv2.destroyAllWindows()

